// 数据库的增删改查api的封装

// user
const userList = {
  insert:
    "INSERT INTO user(user_name,password,no_encrypt,phone,register_time) VALUES(?,?,?,?,?)", // 普通注册
  otherInsert:
    "INSERT INTO user(user_name,password,gender,avatar)VALUES(?,?,?,?)", // 第三方登录
  // 更新
  update(parames) {
    switch (parames) {
      case "user_name":
        return `UPDATE user SET user_name=? WHERE user_id=?`;
      case "nick_name":
        return `UPDATE user SET nick_name=? WHERE user_id=?`;
      case "password":
        return `UPDATE user SET password=? WHERE user_id=?`;
      case "role":
        return `UPDATE user SET role=? WHERE user_id=?`;
      case "gender":
        return `UPDATE user SET gender=? WHERE user_id=?`;
      case "avatar":
        return `UPDATE user SET avatar=? WHERE user_id=?`;
      case "age":
        return `UPDATE user SET age=? WHERE user_id=?`;
      case "phone":
        return `UPDATE user SET phone=? WHERE user_id=?`;
        case 'updateAll':
          return `UPDATE user SET nick_name=?, role=?,gender=?,age=?,avatar=?,user_name=?, phone=? WHERE user_id=?`;
      default:
        return "参数有误";
    }
  },
  delete: "DELETE FROM user WHERE user_id=?",
  queryAll:
    "SELECT age,avatar,gender,nick_name,phone,role,user_id,user_name FROM user WHERE user_id=?",
  // 用于查询登录
  queryUser: "SELECT * FROM user WHERE user_name=?",
  // 用户验证登录
  queryLogin: "SELECT user_name=? FROM user WHERE password=?",
  // 查询用户id
  queryUserId: "SELECT user_id FROM user WHERE user_name=?",
  // 查询密码
  queryPwd: "SELECT * FROM user WHERE password=? AND user_id=?",
};

// goods
const goodsList = {
  queryCategory: "SELECT * FROM goods_category", // 获取商品分类
  queryBrand: "SELECT id,name FROM brand_category WHERE category=?", // 获取商品品牌
  // 获取所有的品牌
  queryAllBrand:`SELECT * FROM brand_category`,
  // 新增商品
  addGoods: `INSERT INTO goods_list(series,title,price,putaway_status,found_id,goods_image,brand_id,category_id,found_time,sure_time,inventory,info) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)`,
  // 获取商品列表
  getList: `SELECT * FROM goods_list LIMIT ?,?`,
  // 编辑商品
  edit_goods: `UPDATE goods_list SET [] WHERE id=?`,
  // 删除商品
  dele_goods: `DELETE  FROM goods_list WEHEW id=?`,
  // 查询商品
  queryKeyword: `SELECT * FROM goods_list WHERE BINARY title=?`,
  // 新增品牌
  addCate:`INSERT INTO brand_category(category,name) VALUES(?,?)`,
 
   // 新增分类
  addBrand:`INSERT INTO goods_category(name) VALUES(?)`,
  // 获取所有的商品分类和商品品牌
  queryCategoryAndBrand:`SELECT * FROM goods_category inner join brand_category ON  brand_category.category=goods_category.id`
};

module.exports = {
  userList,
  goodsList,
};
